//
//  LFBReadBaseCell.m
//  ONE
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 GroupNine. All rights reserved.
//

#import "LFBReadBaseCell.h"

NSString *const kLFBReadBaseCellID = @"LFBReadBaseCellID";

@interface LFBReadBaseCell()

@property (nonatomic, strong) UIImageView *typeImageView;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UILabel *authorLabel;

@property (nonatomic, strong) UILabel *contentLabel;

@property (nonatomic, strong) UIView *bottomLine;

@end

@implementation LFBReadBaseCell

- (void)createCell
{
    if (_typeImageView) {
        return;
    }
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    
//    _typeImageView = ({
//        UIImageView *imageView = [UIImageView new];
//        imageView.backgroundColor = [UIColor whiteColor];
//        [self.contentView addSubview:imageView];
//        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.size.sizeOffset(CGSizeMake(41, 19));
//            make.top.equalTo(self.contentView).offset(16);
//            make.right.equalTo(self.contentView).offset(-10);
//        }];
//        
//        imageView;
//    });
    // 初始化文章类型图片
    _typeImageView = [UIImageView new];
    _typeImageView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_typeImageView];
    [_typeImageView makeConstraints:^(MASConstraintMaker *make) {
        make.size.sizeOffset(CGSizeMake(41, 19));
        make.top.equalTo(self.contentView).offset(16);
        make.right.equalTo(self.contentView).offset(-10);
    }];
    
    // 初始化文章标题Label
    _titleLabel = [UILabel new];
    _titleLabel.textColor = [UIColor colorWithRed:0.26 green:0.26 blue:0.26 alpha:1.00];
    _titleLabel.font = [UIFont boldSystemFontOfSize:18];
    _titleLabel.numberOfLines = 0;
    [self.contentView addSubview:_titleLabel];
    [_titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10);
        make.top.equalTo(_typeImageView);
        make.right.lessThanOrEqualTo(_typeImageView.left).offset(-10);
    }];
    
    // 初始化作者Label
    _authorLabel = [UILabel new];
    _authorLabel.textColor = [UIColor colorWithRed:0.43 green:0.43 blue:0.43 alpha:1.00];
    _authorLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:_authorLabel];
    [_authorLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.bottom).offset(10);
        make.left.right.equalTo(_titleLabel);
    }];
    
    // 初始化内容Label
    _contentLabel = [UILabel new];
    _contentLabel.textColor = [UIColor colorWithRed:0.43 green:0.43 blue:0.43 alpha:1.00];
    _contentLabel.font = [UIFont systemFontOfSize:13];
    _contentLabel.numberOfLines = 0;
    [self.contentView addSubview:_authorLabel];
    [_contentLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_authorLabel.bottom).offset(10);
        make.left.right.equalTo(_authorLabel);
        make.bottom.equalTo(self.contentView).offset(-24);
    }];
    
    // 初始化分割线
    _bottomLine = [UIView new];
    _bottomLine.backgroundColor = [UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1.00];
    [self.contentView addSubview:_bottomLine];
    [_bottomLine makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(0.5);
        make.left.bottom.right.equalTo(self.contentView).insets(UIEdgeInsetsMake(0, 10, 0, 10));
    }];
}

- (void)commonConfigureContentLabelWithText:(NSString *)content
{
    if ((!content || [@"" isEqualToString:content])) {
        return;
    }
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 10;
    NSDictionary *attrsDictionary = @{NSFontAttributeName : _contentLabel.font, NSForegroundColorAttributeName : _contentLabel.textColor, NSParagraphStyleAttributeName : paragraphStyle};
    
    NSAttributedString *attributedString =  [[NSAttributedString alloc] initWithString:content attributes:attrsDictionary];
    _contentLabel.attributedText = attributedString;
}

@end
